﻿# -*- coding: utf-8 -*-
"""
Created on Wed Sep 21 12:40:43 2022

@author: Administrator
"""

import pandas as pd
import json as j
import matplotlib.pyplot as plt
with open('bagua.json','r') as f:
    mydata = j.load(f)

def getDec(ipt):
    up = ipt[0][:3]
    down = ipt[0][3:]
    dong = ipt[1]
    up1 = df.loc[df.num == up]['prop'].values
    down1 = df.loc[df.num == down]['prop'].values
    t = ''
    y = ''
    if(dong >=4 ):
        t = down1
        y = up1
    else:
        t = up1
        y = down1
    return(df1[(df1.y==y[0])&(df1.t==t[0])]['rlt'].values[0])

def getChange(ipt):
    dong = ipt[1]-1
    out = list(ipt[0])
    if(out[dong]=='1'):
        out[dong]='0'
    elif(out[dong]=='0'):
        out[dong]='1'
    return(''.join(out))

def getNext2(ipt):
    head = ipt[0:5]
    return((head+'1',head+'0'))

data = mydata['八卦五行']
data1 =mydata['体用生克']
d1 = mydata['64卦']
d2 = mydata['64卦组成']
d3 = mydata['64卦内容1']
d4 = mydata['64卦内容2']
d5 = mydata['64卦心得']
df = pd.DataFrame(data,columns=['num','name','prop'])
df1 = pd.DataFrame(data1,columns = ['t','y','rlt'])
for i in d5.keys():
    d5[i][3] = (int(d5[i][3]))
    d5[i][1] = (int(d5[i][1]))
l5 = [i for i in d5.values()]
l5 = [[i[j] for i in l5] for j in range(len(l5[0]))]
x = l5[1];y = l5[3]

#顺序完全相反！

while(True):
    
    gua = input('主卦：')
    if(gua ==''):
        break

    gua=gua[::-1]
    (next1,next2) = getNext2(gua)
    print(
        
    )
    outp = ''
    outp = '主卦：' + d5[gua][0] + ' -- ' + d5[gua][2] +'\n\n'
    outp = outp + '明日涨：\n'
    outp = outp + d5[next1][0] + ' -- ' + d5[next1][2] +'\n\n'
    outp = outp + '明日跌：\n'
    outp = outp + d5[next2][0] + ' -- ' + d5[next2][2] +'\n\n'
   
    plt.figure(num = 1,figsize = (19,6.5))
    plt.clf()
    plt.axis([0,65,0,6.5])
    plt.plot(x,y,linestyle = ':')
    plt.text(1, 3.5, outp, fontdict = {
        'family': 'KaiTi', # 标注文本字体
        'fontsize': 14, # 文本大小
        'color': 'black'},  # 文本颜色
        bbox={'facecolor': '#74C476', #填充色
                  'edgecolor':'b',#外框色
                   'alpha': 0.5, #框透明度
                   'boxstyle':'round'
                  }
    )
    plt.text(d5[gua][1], d5[gua][3], d1[gua], fontdict = {
        'family': 'KaiTi', # 标注文本字体
        'fontsize': 20, # 文本大小
        'fontweight': 'bold', # 字体粗细
        'fontstyle': 'italic', # 字体风格
        'color': 'red'},  # 文本颜色
        bbox={'facecolor': '#74C476', #填充色
                  'edgecolor':'b',#外框色
                   'alpha': 0.5, #框透明度
                   'boxstyle':'round'}
    )
    plt.text(d5[next1][1], d5[next1][3], '变1-'+d1[next1], fontdict = {
        'family': 'KaiTi', # 标注文本字体
        'fontsize': 15, # 文本大小
        'fontweight': 'bold', # 字体粗细
        'fontstyle': 'italic', # 字体风格
        'color': 'red'  # 文本颜色
        },
        bbox={'facecolor': 'yellow', #填充色
              'edgecolor':'b',#外框色
               'alpha': 0.5, #框透明度
               'boxstyle':'round'}
    )
    plt.text(d5[next2][1], d5[next2][3], '变0-'+d1[next2], fontdict = {
        'family': 'KaiTi', # 标注文本字体
        'fontsize': 15, # 文本大小
        'fontweight': 'bold', # 字体粗细
        'fontstyle': 'italic', # 字体风格
        'color': 'red'  # 文本颜色
        },
        bbox={'facecolor': 'yellow', #填充色
              'edgecolor':'b',#外框色
               'alpha': 0.5, #框透明度
               'boxstyle':'round'}
    )
    plt.draw()    
    plt.pause(0.001)





